//
//  JSMLeavingMoreProvinceTableViewCell.m
//  TakeYouTourTogether
//
//  Created by dllo on 15/12/3.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMLeavingMoreProvinceTableViewCell.h"
#import "JSMLeavingMoreProvinceCollectionViewCell.h"
#import "JSMLeavingMoreProvinceModel.h"
@interface JSMLeavingMoreProvinceTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property(nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
@property(nonatomic, strong) BaseCollectionView *provinceCollectionView;
@end

@implementation JSMLeavingMoreProvinceTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
// 重写
- (void)setProvincemarr:(NSMutableArray *)provincemarr {
    if (_provincemarr != provincemarr) {
        _provincemarr = provincemarr;
        [self.provinceCollectionView reloadData];
    }
}


- (void)createView {
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//    self.provinceCollectionView = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT) collectionViewLayout:self.flowLayout];
    self.provinceCollectionView = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:self.flowLayout];
    [self.contentView addSubview:self.provinceCollectionView];
    self.provinceCollectionView.dataSource = self;
    self.provinceCollectionView.delegate = self;
    [self.provinceCollectionView registerClass:[JSMLeavingMoreProvinceCollectionViewCell class] forCellWithReuseIdentifier:@"provinceCollectionView"];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.flowLayout.itemSize = CGSizeMake(TableViewCellWidth * 3 / 10, TableViewCellHeight * 7 / 8);
    self.provinceCollectionView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.provincemarr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    JSMLeavingMoreProvinceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"provinceCollectionView" forIndexPath:indexPath];
    [cell.provinceImageView sd_setImageWithURL:[NSURL URLWithString:[self.provincemarr[indexPath.row] iconStr]] placeholderImage:PlaceHolderImage];
    cell.provinceLabel.text = [self.provincemarr[indexPath.row] nameStr];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self.delegate pushToDetailsPage:[self.provincemarr[indexPath.row] nameStr]];
}

@end
